﻿using System;
class MostFrequentElement
{
    static void Main()
    {
        int currentEl = 0;
        int mostFreqEl = 0;
        int currentIndex = 0;
        int lenght;
        Console.Write("please enter the lenght of array: ");
        while (true)
        {
            try
            {
                lenght = int.Parse(Console.ReadLine());
                break;
            }
            catch (Exception)
            {
                Console.Write("Please re-enter lenght:");
            }
        }
        int[] theArray;
        theArray = new int[lenght];
        for (int i = 0; i < lenght; i++)
        {
            Console.Write("Please enter the {0} element of array: ", i);
            while (true)
            {
                try
                {
                    theArray[i] = int.Parse(Console.ReadLine());
                    break;
                }
                catch (Exception)
                {
                    Console.Write("Please re-enter element:");
                }
            }
        }
        for (int i = 0; i < lenght; i++)
        {
            currentEl = 1;
            for (int j = 0; j < lenght; j++)
            {
                if (theArray[i] == theArray[j])
                {
                    currentEl++;
                }
            }
            currentEl--;
            if (currentEl > mostFreqEl)
            {
                mostFreqEl = currentEl;
                currentIndex = i;
            }
        }
        Console.WriteLine("The number {0} is most frequent - {1} times", theArray[currentIndex], mostFreqEl);
        Console.ReadLine();
    }
}

